package org.itboys.core.entity.mysql.coupon;

import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.itboys.mysql.entity.BaseMySqlEntity;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
*@Author: jiaqilei
*@Date: 9:52 2018/12/10
*@Discription:优惠券
*/
@Data
public class SundayCoupon extends BaseMySqlEntity{
    /**优惠券金额*/
    private BigDecimal money;
    /**图标*/
    private String image;
    /**类型1:邀请好友赠送，2：系统分发*/
    private Integer type;
    /**生效日期*/
    private String startDate;
    /**结束日期*/
    private String endDate;

    /**状态：0过期，1：有效*/
    public Integer getState() throws ParseException {
        if(StringUtils.isNotEmpty(endDate)){
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            Date _endDate = sdf.parse(endDate);
            return _endDate.compareTo(new Date())<0?0:1;
        }
        return null;
    }
}